﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZG_member.Model;
using System.Data.SqlClient;
using System.Data;
using Maticsoft.DBUtility;
namespace ZG_member.DAL
{
    public class birthdayremind
    {
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ZG_member.Model.birthdayremind GetModel(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,remindday,remindcontent,Nowremindcontent,birthdaydiscount from birthdayremind ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)};
            parameters[0].Value = id;

            ZG_member.Model.birthdayremind model = new ZG_member.Model.birthdayremind();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["remindday"] != null && ds.Tables[0].Rows[0]["remindday"].ToString() != "")
                {
                    model.Remindday = int.Parse(ds.Tables[0].Rows[0]["remindday"].ToString());
                }
                if (ds.Tables[0].Rows[0]["remindcontent"] != null && ds.Tables[0].Rows[0]["remindcontent"].ToString() != "")
                {
                    model.Remindcontent = ds.Tables[0].Rows[0]["remindcontent"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Nowremindcontent"] != null && ds.Tables[0].Rows[0]["Nowremindcontent"].ToString() != "")
                {
                    model.Nowremindcontent1 = ds.Tables[0].Rows[0]["Nowremindcontent"].ToString();
                }
                if (ds.Tables[0].Rows[0]["birthdaydiscount"] != null && ds.Tables[0].Rows[0]["birthdaydiscount"].ToString() != "")
                {
                    model.Birthdaydiscount = ds.Tables[0].Rows[0]["birthdaydiscount"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }
        public int tixingday(string id)
        {
            return DbHelperSQL.Getdays(id);
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from birthdayremind");
            strSql.Append(" where id=@id ");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
            parameters[0].Value = id;


            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
         

        //添加数据
        public bool add(ZG_member.Model.birthdayremind model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into birthdayremind(");
            strSql.Append("remindday,remindcontent,Nowremindcontent,birthdaydiscount)");
            strSql.Append(" values (");
            strSql.Append("@remindday,@remindcontent,@Nowremindcontent,@birthdaydiscount)");
            SqlParameter[] parameters = {
					
					new SqlParameter("@remindday", SqlDbType.Int,4),
					new SqlParameter("@remindcontent", SqlDbType.NVarChar,200),
					new SqlParameter("@Nowremindcontent", SqlDbType.NVarChar,200),
					new SqlParameter("@birthdaydiscount", SqlDbType.NVarChar,200),};

            parameters[0].Value = model.Remindday;
            parameters[1].Value = model.Remindcontent;
            parameters[2].Value = model.Nowremindcontent1;
            parameters[3].Value = model.Birthdaydiscount;
            object obj = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        
            if (obj == null)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        //更改数据
        public bool Update(ZG_member.Model.birthdayremind model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update birthdayremind set ");
            strSql.Append("remindday = @remindday ,");
            strSql.Append("remindcontent = @remindcontent,");
            strSql.Append("Nowremindcontent = @Nowremindcontent,");
            strSql.Append("birthdaydiscount = @birthdaydiscount");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					
					new SqlParameter("@remindday", SqlDbType.Int,4),
					new SqlParameter("@remindcontent", SqlDbType.NVarChar,200),
					new SqlParameter("@Nowremindcontent", SqlDbType.NVarChar,200),
					new SqlParameter("@birthdaydiscount", SqlDbType.NVarChar,200),
					new SqlParameter("@id", SqlDbType.Int,4)};
            parameters[0].Value = model.Remindday;
            parameters[1].Value = model.Remindcontent;
            parameters[2].Value = model.Nowremindcontent1;
            parameters[3].Value = model.Birthdaydiscount;
            parameters[4].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}
